package com.example.park2212.visitor

import androidx.appcompat.app.AppCompatActivity
import android.os.Bundle
import android.widget.ImageView
import com.alibaba.android.arouter.facade.annotation.Route
import com.blankj.utilcode.util.ToastUtils
import com.example.lib_base.entity.VisitBean
import com.example.lib_base.entity.VisitBeanItem
import com.example.lib_base.mvvm.BaseActivity
import com.example.lib_base.net.Const
import com.example.park2212.R
import com.example.park2212.databinding.ActivityVisitAddBinding
import dagger.hilt.android.AndroidEntryPoint

@AndroidEntryPoint
@Route(path = "/app/visitor/VisitAddActivity")
class VisitAddActivity : BaseActivity<ActivityVisitAddBinding,VisitorViewModel>() {
    override fun initView() {
        binding.headVisitAdd.headerTitle.setText("来访登记")
        binding.headVisitAdd.headerAdd.apply {
            setImageResource(R.drawable.ic_action_ok)
        }
        binding.headVisitAdd.headerAdd.setOnClickListener {
            val user = binding.visitaddUser.text.toString()
            val phone = binding.visitaddPhone.text.toString()
            val car = binding.visitaddCard.text.toString()
            val date = binding.visitaddDate.text.toString()
            val purpose = binding.visitaddPurpose.text.toString()
            val carNo = binding.visitaddCarNo.text.toString()
            val emp = binding.visitaddEmp.text.toString()
            val item = VisitBeanItem(
                date, false, listOf(
                    "http://example.com/photo1.jpg",
                    "http://example.com/photo2.jpg"
                ), emp.toInt(), 3, car, phone, carNo,
                purpose, true, "待审核", user
            )
            viewModel.visitAdd(item)
        }


        binding.visitaddIvdate.setOnClickListener {//来访日期
            showDateDialog(binding.visitaddDate)
        }

        binding.visitaddIvstart.setOnClickListener {//开始时间
            showTimeDialog(binding.visitaddStart)
        }

        binding.visitaddIvend.setOnClickListener {//结束时间
            showTimeDialog(binding.visitaddEnd)
        }



      binding.visitaddSwitch.setOnCheckedChangeListener { compoundButton, b ->
          binding.visitaddCarNo.isEnabled = b
      }


    }

    override fun initData() {
        viewModel.visitAddSuccess.observe(this){
            ToastUtils.showLong("添加成功")
            finish()
        }
    }

}